package ui.swing.mechanics;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JWindow;
import javax.swing.WindowConstants;

public class App11 {

	public static void main(String[] args) {
		
		final JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		frame.setSize(100, 140);
		//frame.setUndecorated(true); // like JWindow
		frame.setExtendedState(Frame.MAXIMIZED_BOTH);
		frame.setExtendedState(Frame.ICONIFIED);
		frame.setExtendedState(Frame.NORMAL);
		
		Dimension dim = frame.getToolkit().getScreenSize();
		
		frame.setLocation(dim.width/2 - frame.getWidth()/2,
				dim.height/2 - frame.getHeight()/2);
		
		
		
		frame.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				int confirm = JOptionPane.showConfirmDialog(frame, "是否要退出？","确认",JOptionPane.YES_NO_OPTION);
				if (confirm == JOptionPane.OK_OPTION)
				{
					frame.dispose();
				}
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				JOptionPane.showMessageDialog(frame, "您已经退出","提示",JOptionPane.INFORMATION_MESSAGE);
				System.exit(0);
			}
		});
		frame.setVisible(true);
	}
}

class App21 {

	public static void main(String[] args) {
		
		final JWindow win = new JWindow();
		//win.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		win.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				int confirm = JOptionPane.showConfirmDialog(win, "是否要退出？","确认",JOptionPane.YES_NO_OPTION);
				if (confirm == JOptionPane.OK_OPTION)
				{
					win.dispose();
				}
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				JOptionPane.showMessageDialog(win, "您已经退出","提示",JOptionPane.INFORMATION_MESSAGE);
				System.exit(0);
			}
		});
		//win.setSize(new Dimension(100,200));
		win.setBounds(new Rectangle(100,200,300,400));
		win.setVisible(true);
	}
}
